home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5913 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  43 lines

  1. Newsgroups: comp.lang.c
  2. Path: netcom.com!cader
  3. From: cader@netcom.com (Charles Ader)
  4. Subject: Re: Tough FACTORIAL math problem...
  5. Message-ID: <caderDn5G9L.9oM@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. X-Newsreader: TIN [version 1.2 PL1]
  8. References: <4fr8be$ass@news.iconn.net> <31224679.6193@born.com> <312A49F0.167E@silk.gsfc.nasa.gov>
  9. Date: Wed, 21 Feb 1996 23:36:57 GMT
  10. Sender: cader@netcom7.netcom.com
  11.  
  12. I have been thinking about this problem for a few days. It
  13. occured to me that it may be possible to find the answer
  14. to the question of "What is the least significant non-zero
  15. digit of N!?" by using an 8 by 8 multiplier table.
  16.  
  17. The input would be the stream of digits from 2 to N! but the
  18. digit values of 0 and 1 are elminated because they do not
  19. affect the result of the multiplication.
  20.  
  21. Also elminate pairs of 2s and 5s.
  22.  
  23. For example 12! = 479,001,600
  24.  
  25. The raw input stream is: 123456789101112
  26. Throw out all the 1s and 0s: 234567892
  27. Removes pairs of 2s and 5s:  3467892
  28. Multiply the digit stream: 3*4*6*7*8*9*2 = 72,576
  29. (Only the least significant digit means anything.)
  30.  
  31. Note:
  32.  The multiply step only needs to keep the least signifcant two
  33.  digits because all the factors of 10 have been removed from 
  34.  the input stream.
  35.  
  36. This scheam seems to work for 12! and 13!
  37.  
  38. I didn't see any of the messages in this thread using this
  39. approach.
  40.  
  41.  
  42. Charles.
  43.